$(function () {
    var $register = $("#register");
    var $login = $("#login");
    var $status = $("#status")
    //注册接口请求
    $("#registerBtn").on('click',function () {
        $.ajax({
            type:'post',
            url:'/api/user/register',
            data: {
                username:$register.find('[name="username"]').val(),
                password:$register.find('[name="userpassword"]').val(),
                repassword:$register.find('[name="reuserpassword"]').val(),
            },
            dataType:'json',
            success:function (result) {
                $('#register_info').html(result.message);
            }
        })
    })

    //登录接口请求
    $("#login_btn").on('click',function () {
        $.ajax({
            type:'post',
            url:'/api/user/login',
            data: {
                username:$login.find('[name="username"]').val(),
                password:$login.find('[name="userpassword"]').val(),
            },
            dataType:'json',
            success:function (result) {
                $('#login_info').html(result.message);
                if (result.code == 7) {
                    window.location.reload();//重载页面
                }
            }
        })
    })

    //退出登录请求
    $("#logout").on('click',function () {
        $.ajax({
            type:'post',
            url:'/api/user/logout',
            success:function (result) {
                if (result.code == 8) {
                    window.location.reload();//重载页面
                }
            }
        })
    })
})